package customer.GUI.components.panels;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import customer.core.InitManager;
import customer.core.ctrl.ChatControlIo;

public class NetPlayCustomChanPanel extends JPanel implements ActionListener{

	/**
	 * Components
	 */
	private JButton btnSend = new JButton("Send");
	private JTextField jtfText = new JTextField();
	private JPanel senderPanel = new JPanel();
	private JTextArea messagesContainer= new JTextArea();
	private String currentGameName;
	
	public NetPlayCustomChanPanel(String gameName)
	{
		super();
		
		currentGameName = gameName;
		
		buildUI();
	}

	private void buildUI() {
		this.setLayout(new BorderLayout());
		senderPanel.setLayout(new GridLayout(1,2));
		senderPanel.add(jtfText);
		btnSend.setSize(new Dimension(70, btnSend.getHeight()));
		btnSend.setActionCommand("sendMsg");
		btnSend.addActionListener(this);
		senderPanel.add(btnSend);
		
		this.add(messagesContainer, BorderLayout.CENTER);
		this.add(senderPanel, BorderLayout.SOUTH);
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("sendMsg"))
		{
			ChatControlIo io = new ChatControlIo();
			io.connect(InitManager.getCurrentUser(), currentGameName);
			io.sendMessage(null, null, "TEST CACA", 8);
		}
		
	}
	
	
}
